package com.itheima;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class jdbc {
    public static void main(String[] args) throws Exception {
        //1注册驱动
        Class.forName("com.mysql.jdbc.Driver");

        //2获取连接
        String url = "jdbc:mysql://localhost:3306/sample_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
        String username = "root";
        String password = "";
        Connection conn = DriverManager.getConnection(url, username, password);

        //3定义SQL语句
        String sql = "update t_user set sex = '女' where uid =2;";

        //4获取执行SQL的对象statement
        Statement stmt = conn.createStatement();

        //5执行SQL
        int cont = stmt.executeUpdate(sql);

        //*6处理结果
        System.out.println(cont);

        //7释放资源
        stmt.close();
        conn.close();
    }
}
